/* McSocket.h
 *
 * --
 * Copyright (c) 2012, Christophe Huriaux
 * Distributed under the terms of the MIT license.
 * http://www.opensource.org/licenses/mit-license.php
 * --
 */

#ifndef MCSOCKET_H
#define MCSOCKET_H

#include <socket/ClientSocket.h>
#include <packet/McPacket.h>
#include <packet/packets.h>
#include <thread/thread.h>
#include <ostream>
#include <queue>


class McSocket : public Thread
{
	ClientSocket socket;
	pthread_mutex_t packetMutex;
	std::queue<McPacketFromServer*>	packetQueue;

public:
	McSocket(const char* mcServer, int serverPort);


protected:
	void* run();

public:
	int open();
	int close();

	ClientSocket& getSocket() { return socket; }

	McSocket& operator<<(McPacketToServer& packet);
	McSocket& operator>>(McPacketFromServer*& packet);
	unsigned int queue_size();
};
#endif
